import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            // 注意 hasNext 和 hasNextLine 的区别
            while (in.hasNextLine()) { // 注意 while 处理多个 case
                String str=in.nextLine();
                BianarTree.TreeNode root= createTree(str);
                nextOder(root);
            }
        }

        public static int i=0;
        public static BianarTree.TreeNode createTree(String str){
            BianarTree.TreeNode root=null;
            if(str.charAt(i)!='#'){
                root=new BianarTree.TreeNode(str.charAt(i));
                i++;
                root.left=createTree(str);
                root.right=createTree(str);
            }else{
                i++;
            }
            return root;
        }
        public static void nextOder(BianarTree.TreeNode root) {
            if (root == null) {
                return;
            }
            nextOder(root.left);
            System.out.print(root.val + " ");
            nextOder(root.right);

        }
}
